package com.ncloud.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.ncloud.crm.entity.order.OrderCustomer;

/**
 * Created by shiqiang on 2017/4/11.
 */
@Mapper
public interface OrderCustomerMapper {
    @Select(value = { "select * from bs_o_cust where order_id = #{orderId}" })
    @Results({ @Result(column = "order_id", property = "orderId"), @Result(column = "cust_id", property = "custId"),
            @Result(column = "modify_tag", property = "modifyTag"),@Result(column = "cust_name", property = "custName"),
            @Result(column="create_user",property="createUser"),@Result(column="create_time",property="createTime"),
            @Result(column="update_user",property="updateUser"),@Result(column="company_code",property="companyCode"),
            @Result(column="update_time",property="updateTime"),@Result(column="remark",property="remark"),
            @Result(column="industry",property="industry"),@Result(column = "contact_email", property = "contactEmail"),
            @Result(column = "contact_name", property = "contactName"),@Result(column = "contact_phone", property = "contactPhone")
    })
    public List<OrderCustomer> getByOrderId(Long orderId);
    @Insert(value = "insert into bs_o_cust(order_id,cust_id,modify_tag,cust_name,company_code,create_user,industry,contact_email," +
            "create_time,update_user,update_time,remark,contact_name,contact_phone) values (#{orderId},#{custId},#{modifyTag},#{custName},#{companyCode},#{createUser}," +
            "#{industry},#{contactEmail},#{createTime},#{updateUser},#{updateTime},#{remark},#{contactName},#{contactPhone})")
    public int insertOrderCustomer(OrderCustomer orderCustomer);

    @Select("select * from bs_o_cust where company_code=#{companyCode} limit 1")
    @Results({ @Result(column = "order_id", property = "orderId"), @Result(column = "cust_id", property = "custId"),
            @Result(column = "modify_tag", property = "modifyTag"),@Result(column = "cust_name", property = "custName"),
            @Result(column="create_user",property="createUser"),@Result(column="create_time",property="createTime"),
            @Result(column="update_user",property="updateUser"),@Result(column="company_code",property="companyCode"),
            @Result(column="update_time",property="updateTime"),@Result(column="remark",property="remark"),
            @Result(column="industry",property="industry"),@Result(column = "contact_email", property = "contactEmail"),
            @Result(column = "contact_name", property = "contactName"),@Result(column = "contact_phone", property = "contactPhone")
    })
    OrderCustomer getByCompanyCode(String companyCode);

    @Select("select a.* from bs_o_cust a,bs_o_order b  where a.order_id=b.order_id and contact_email =#{contactEmail}")
    @Results({ @Result(column = "order_id", property = "orderId"), @Result(column = "cust_id", property = "custId"),
            @Result(column = "modify_tag", property = "modifyTag"),@Result(column = "cust_name", property = "custName"),
            @Result(column="create_user",property="createUser"),@Result(column="create_time",property="createTime"),
            @Result(column="update_user",property="updateUser"),@Result(column="company_code",property="companyCode"),
            @Result(column="update_time",property="updateTime"),@Result(column="remark",property="remark"),
            @Result(column="industry",property="industry"),@Result(column = "contact_email", property = "contactEmail"),
            @Result(column = "contact_name", property = "contactName"),@Result(column = "contact_phone", property = "contactPhone")
    })
    List<OrderCustomer> getCustByEmail(String contactEmail);
    
    @Select("select a.* from bs_o_cust a,bs_o_order b where a.order_id=b.order_id and cust_id =#{custId}")
    @Results({ @Result(column = "order_id", property = "orderId"), @Result(column = "cust_id", property = "custId"),
            @Result(column = "modify_tag", property = "modifyTag"),@Result(column = "cust_name", property = "custName"),
            @Result(column="create_user",property="createUser"),@Result(column="create_time",property="createTime"),
            @Result(column="update_user",property="updateUser"),@Result(column="company_code",property="companyCode"),
            @Result(column="update_time",property="updateTime"),@Result(column="remark",property="remark"),
            @Result(column="industry",property="industry"),@Result(column = "contact_email", property = "contactEmail"),
            @Result(column = "contact_name", property = "contactName"),@Result(column = "contact_phone", property = "contactPhone")
    })
	public List<OrderCustomer> getByCustId(Long custId);
}
